<p class="Paragraph">Calls a subroutine within a Sub or Function indicated by a label. The statements following the label are executed until the next Return statement; thereafter the program continues with the statement following the <span style="font-weight:bold;">GoSub </span>statement.</p>
<p class="Paragraph">The <span class="T1">GoSub</span> statement is used to call a local subroutine from within a Sub or Function, indicated by a label that marks the first line of the subroutine. To name of the label must end with a colon (":"). After reaching the <span class="T1">GoSub</span> statement, the program continues execution with the statement directly following the label. The subsequent statements and functions are executed until the next <span class="T1">Return</span> statement. The program then returns to the <span class="T1">GoSub</span> statement and continues with the statement following the <span class="T1">GoSub</span> statement.</p>
<p class="TextInTable">If the program encounters a Return statement not preceded by <span class="T1">GoSub</span>, Star Basic returns an error message. Use <span class="T1">Exit Sub</span> or <span class="T1">Exit Function</span> to ensure that the program leaves a Sub or Function before reaching the next Return statement.</p>
<p class="TextInTable">GoSub and Return are relicts from old BASIC dialects, retained only for compatibility reasons. If you often use GoSub and Return, your program will tend to become unreadable. Subs or Functions are preferable.</p>
</span></th></tr></table>
<p class="Paragraph"/>
<p class="Paragraph">The following example demonstrates the use of <span class="T1">GoSub</span> and <span class="T1">Return </span>. By executing a program section twice, the program calculates the square root of two numbers entered by the user.</p>